import {
  reqGetBaseCategoryList,
  reqGetBanners,
  reqGetFloors,
} from "@/api/home";

// vuex模块
export default {
  namespaced: true,
  state: {
    // 首页三级分类列表
    baseCategoryList: [],
    banners: [],
    floors: [],
  },
  actions: {
    async getBaseCategoryList({ commit }) {
      const baseCategoryList = await reqGetBaseCategoryList();
      commit("GET_BASE_CATEGORY_LIST", baseCategoryList.slice(0, -1));
    },
    async getBanners({ commit }) {
      const banners = await reqGetBanners();
      commit("GET_BANNERS", banners);
    },
    async getFloors({ commit }) {
      const floors = await reqGetFloors();
      commit("GET_FLOORS", floors);
    },
  },
  mutations: {
    GET_BASE_CATEGORY_LIST(state, baseCategoryList) {
      state.baseCategoryList = baseCategoryList;
    },
    GET_BANNERS(state, banners) {
      state.banners = banners;
    },
    GET_FLOORS(state, floors) {
      state.floors = floors;
    },
  },
};
